<?php
/**
 *	Architect Framework
 *
 *	Architect Framework is a light weight object oriented web applications framework written for PHP 5.1.4 and later that provide the tools to develop and deploy a website or application fast and with as little code as possible.
 *
 *	@author Robin Grass, <hello@coffinboy.se>
 *	@link http://architect.kodlabbet.net
 *	@license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License (v. 3)
 */

/**
 *	af_autoload
 *
 *	Autoloader callback function.
 *
 *	@param string $file_path
 */
function af_autoload($class) {
	Architect_Autoloader::load($class);
}

/**
 *	af_load
 *
 *	A shortcut function to load a file within the framework.
 *
 *	@param string $file_path
 */
function af_load($file_path, $use_prefix = false) {
	if($use_prefix)
		require_once(ARCH_ROOT_PATH . $file_path);
require_once($file_path);
}

/**
 *	af_redirect
 *
 *	This function redirects, either by a simple refresh or by changing the location header.
 *
 *	@param string $uri
 *	@param string $method
 *	@param int $http_response
 */
function af_redirect($uri, $method = 'location', $http_response = 302) {
	switch($method) {
		case 'refresh' :
			header('Refresh:0;url=' . $uri);
			break;
		default :
			header('Location: ' . $uri, true, $http_response);
		break;
	}
}

/**
 *	af_randstr
 *
 *	This function returns a randomly generated string.
 *
 *	@param string $type
 *	@param int $length
 *
 *	@return string|int
 */
function af_randstr($type = 'alnum', $length = 8) {
	switch($type) {
		case 'alnum' :
		case 'numeric' :
		case 'nozero' :
			switch($type) {
				case 'alnum' :
					$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
					break;
				case 'numeric' :
					$pool = '0123456789';
					break;
				case 'nozero' :
					$pool = '123456789';
					break;
			}
			$str = '';
			for($n = 0; $n < $length; $n++)
				$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
			return $str;
		break;
		case 'unique' :
			return md5(uniqid(mt_rand()));
		break;
	}
}
?>